package com.gy.controller.research;

import com.gy.controller.common.UserHolder;
import com.gy.result.Result;
import com.gy.service.impl.SummaryCacheService;
import com.gy.vo.summary.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/summary")
@CrossOrigin
public class SummaryController {
    @Autowired
    private SummaryCacheService summaryCacheService;

    @GetMapping("/getCertifications")
    @ApiOperation("获取档案资料汇总信息")
    public Result<List<CertificationVO>> getCertificationSummary() {
        Long userId = UserHolder.getUser().getUserId();
        if (userId == null) {
            return Result.error("用户未登录或信息异常");
        }
        return Result.success(summaryCacheService.getCertificationSummary(userId));
    }

    @GetMapping("/getEducation")
    @ApiOperation("获取继续教育材料信息")
    public Result<List<ContinueEducationMaterialVO>> getEducationSummary() {
        Long userId = UserHolder.getUser().getUserId();
        if (userId == null) {
            return Result.error("用户未登录或信息异常");
        }
        return Result.success(summaryCacheService.getEducationSummary(userId));
    }

    @GetMapping("/getCopyRights")
    @ApiOperation("获取软件著作权信息")
    public Result<List<CopyRightVO>> getCopyRightsSummary() {
        Long userId = UserHolder.getUser().getUserId();
        if (userId == null) {
            return Result.error("用户未登录或信息异常");
        }
        return Result.success(summaryCacheService.getCopyRightsSummary(userId));
    }

    @GetMapping("/getOther")
    @ApiOperation("获取其他信息")
    public Result<List<OtherVO>> getOtherSummary() {
        Long userId = UserHolder.getUser().getUserId();
        if (userId == null) {
            return Result.error("用户未登录或信息异常");
        }
        return Result.success(summaryCacheService.getOtherSummary(userId));
    }

    @GetMapping("/getPapersSummary")
    @ApiOperation("获取论文汇总")
    public Result<List<PapersVO>> getPapersSummary() {
        Long userId = UserHolder.getUser().getUserId();
        if (userId == null) {
            return Result.error("用户未登录或信息异常");
        }
        return Result.success(summaryCacheService.getPapersSummary(userId));
    }

    @GetMapping("/getPatentsBySummary")
    @ApiOperation("汇总表格中返回专利信息")
    public Result<List<PatentsVO>> getPatentsBySummary() {
        Long userId = UserHolder.getUser().getUserId();
        if (userId == null) {
            return Result.error("用户未登录或信息异常");
        }
        return Result.success(summaryCacheService.getPatentsSummary(userId));
    }
}
